package org.android.cosmus.indiam.tasks;

import org.android.cosmus.indiam.R;
import org.android.cosmus.indiam.utilities.Utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.os.AsyncTask;

public class CheckConnectionTask extends AsyncTask<Void, Void, Boolean>
{
  private Context m_context;

  public CheckConnectionTask(Context context)
  {
    super();
    this.m_context = context;
  }
  
  @Override
  protected Boolean doInBackground(Void... params)
  {
    ConnectivityManager connManager = (ConnectivityManager) m_context.getSystemService(Context.CONNECTIVITY_SERVICE);
    return (connManager.getActiveNetworkInfo() != null && connManager.getActiveNetworkInfo().isAvailable() && connManager.getActiveNetworkInfo().isConnected());
  }

  @Override
  protected void onPostExecute(Boolean isConnected)
  {
    super.onPostExecute(isConnected);
    if (!isConnected)
    {
      String text = m_context.getString(R.string.connection_error);
      Utils.makeToast(m_context, text);
    }
  }
}
